<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container" style="display: flex;">
          <el-form inline size="small" :model="userFrom" ref="userFrom" :label-position="labelPosition"  label-width="100px" style="display: flex;">
                  <el-form-item label="用户搜索：" style="margin-bottom:0!important;display:flex;">
                    <el-input v-model="userFrom.name" placeholder="请输入姓名或手机号" clearable  class="selWidth"/>
                  </el-form-item>
                  <el-form-item label="村组" style="margin-bottom:0!important;display:flex;"  v-if="identity===1">
                    <el-cascader  class="selWidth"
                                 v-model="userFrom.villageId"
                                 :options="villageList"
                                 :props="optionProps"
                                 @change="handleChange"></el-cascader>
                  </el-form-item>
                  <el-form-item label="审核状态" style="margin-bottom:0!important;display:flex;margin-right: 30px;">
                    <el-select v-model="userFrom.auditStatus" placeholder="状态" clearable class="selWidth">
                      <el-option label="未实名" :value="1"/>
                      <el-option label="已通过" :value="2"/>
                      <el-option label="待审核" :value="3"/>
                      <el-option label="已拒绝" :value="4"/>
                    </el-select>
                  </el-form-item>
                <el-form-item style="margin-bottom:0!important;">
                  <el-button label="default" class="" icon="el-icon-search" size="mini" type="primary"  @click="userSearchs">搜索</el-button>
                  <el-button class="ResetSearch mr10" @click="reset('userFrom')" icon="el-icon-refresh" size="mini">重置</el-button>
                </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table
        ref="table"
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border
        >
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="近次访问时间：">
                <span>{{ props.row.lastLoginTime | filterEmpty }}</span>
              </el-form-item>
              <el-form-item label="近次访问IP：">
                <span>{{ props.row.lastLoginIp | filterEmpty }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column
          prop="id"
          label="ID"
          min-width="60"
        />
        <el-table-column
        label="头像" min-width="80">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image
                style="width: 36px; height: 36px"
                :src="scope.row.avatar"
                :preview-src-list="[scope.row.avatar]"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="真实姓名"
          min-width="120"
        >
          <template slot-scope="scope">
            <span>{{scope.row.name | filterEmpty  }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="手机号"
          min-width="120"
        >
          <template slot-scope="scope">
            <span>{{scope.row.phoneNumber | filterEmpty}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="身份证号"
          min-width="120"
        >
          <template slot-scope="scope">
            <span>{{scope.row.idCard | filterEmpty}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="村组"
          min-width="120"
        >
          <template slot-scope="scope">
            <span>{{scope.row.villageText | filterEmpty}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          min-width="80"
        >
          <template slot-scope="scope">
            <span>{{scope.row.auditStatusText| filterEmpty}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="integral" label="积分额" min-width="120"/>
        <el-table-column label="操作" min-width="130" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button icon="el-icon-eye" type="primary" @click="handlerOpenEdit(scope.row)" size="mini" v-hasPermi="['admin:user:check']" v-if="scope.row.auditStatus!==1">审核</el-button>
            <el-button icon="el-icon-eye" type="primary" @click="onDetails(scope.row.id)" size="mini" v-hasPermi="['admin:user:info']">详情</el-button>
          </template>
        </el-table-column>
        </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[15, 30, 45, 60]"
          :page-size="userFrom.limit"
          :current-page="userFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <el-dialog
      :visible.sync="editDialogConfig.visible"
      title="用户审核"
      destroy-on-close
      :close-on-click-modal="false"
      width="700px"
    >
      <checkEdit
        v-if="editDialogConfig.visible"
        :edit-data="editDialogConfig.editData"
        @hideEditDialog="hideEditDialog"
      />
    </el-dialog>
    <!--详情-->
    <el-dialog
      title="用户详情"
      :visible.sync="Visible"
      width="1100px"
    >
      <user-details ref="userDetails" :id="id" v-if="Visible" @close="close"></user-details>
    </el-dialog>
  </div>
</template>

<script>
  import { userListApi} from '@/api/user'
  import userDetails from './userDetails'
  import Cookies from 'js-cookie'
  import { checkPermi } from "@/utils/permission"; // 权限判断函数
  import checkEdit from './checkEdit'
  import {Debounce} from '@/utils/validate'
  import { selectTreeApi } from '@/api/systemadmin'
  export default {
    name: 'UserIndex',
    components:{ userDetails ,checkEdit},
    data() {
      return {
        loadingBtn: false,
        Visible: false,
        labelPosition:'right',
        collapse: false,
        props: {
          children: 'child',
          label: 'name',
          value: 'name',
          emitPath: false
        },
        listLoading: true,
        tableData: {
          data: [],
          total: 0
        },
        userFrom: {
          //accessType: 0,
          name: '',
          page: 1,
          limit: 15,
          villageId:[],
          auditStatus:null
        },
        grid: {
          xl: 8,
          lg: 12,
          md: 12,
          sm: 24,
          xs: 24
        },
        editDialogConfig: {
          visible: false,
          editData: {}
        },
        loading: false,
        id: null,
        optionProps: {
          value: 'id',
          label: 'name',
          children: 'children',
        },
        villageList:[],
      }
    },
    activated(){
      this.userFrom.name = '';
      this.getList(1);
    },
    mounted() {
      this.getList()
      this.selectTreeList()
    },
    computed: {
      identity() {
        return this.$store.getters.id
      }
    },
    methods: {
      handleChange(value) {
        this.userFrom.villageId=value
      },
      selectTreeList() {
        selectTreeApi().then(data => {
          this.villageList = data
        })
      },
      handlerOpenEdit(editDate) {
        console.log(editDate)
        this.editDialogConfig.editData = editDate
        this.editDialogConfig.visible = true
      },
      hideEditDialog() {
        this.editDialogConfig.visible = false
        this.getList()
      },
      checkPermi,

      reset(formName) {
        this.userFrom = {
            //accessType: 0,
            name: '',
            page: 1,
            limit: 15,
           villageId: [],
          auditStatus:''
        }
        this.getList()
      },

      close() {
        this.Visible = false
        this.getList()
      },
      // 账户详情
      onDetails(id){
        this.id = id
        this.Visible = true
      },

      // 搜索
      userSearchs () {
        this.userFrom.page = 1;
        this.getList();
      },

      // 列表
      getList(num) {
        this.listLoading = true
        this.userFrom.page = num ? num : this.userFrom.page;
        if(this.userFrom.villageId.length>0){
          this.userFrom.villageId=this.userFrom.villageId[2]
        }
        userListApi(this.userFrom).then(res => {
        //后期接口调用
          this.tableData.data = res.list
          this.tableData.total = res.count
          this.listLoading = false
        }).catch(() => {
          this.listLoading = false
        })
      },

      pageChange(page) {
        this.userFrom.page = page
        this.getList()
      },
      handleSizeChange(val) {
        this.userFrom.limit = val
        this.getList()
      },
    }
  }
</script>

<style scoped lang="scss">
  /*.timeBox{*/
    /*width: 100%;*/
    /*::v-deep.el-form-item__content{*/
      /*width: 87% !important;*/
    /*}*/
  /*}*/
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
    font-size: 12px;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .text-right{
    text-align: right;
  }
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 33.33%;
  }
  .selWidth{
    width: 100% !important;
  }
  .seachTiele{
    line-height: 30px;
  }
  .container{
    min-width: 821px;
    ::v-deep.el-form-item{
      width: 100%;
    }
    ::v-deep.el-form-item__content{
      width: 72%;
    }
  }
  .ivu-ml-8{
    font-size: 12px;
    color: #1682e6;
  }
  .btn_bt{
    border-top:1px dashed #ccc;
    padding-top: 20px;
  }
  .relative{
    position: relative;
  }
  .pictrue{
    width: 250px;
    height: 180px;
    border: 1px dotted rgba(0,0,0,0.1);
    margin-right: 10px;
    position: relative;
    cursor: pointer;
    .photo-el-image{
      width: 100%;
      height: 100%;
    }
    img{
      width: 100%;
      height: 100%;
    }
    video{
      width: 100%;
      height: 100%;
    }
  }
</style>
